package com.zr.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.zr.model.Cuser;
import com.zr.service.UpdateDisstationService;

public class UpdateDisstationAction extends ActionSupport implements SessionAware,ServletResponseAware{

	
	private HttpServletResponse resp;
	private Map<String, Object> session;
	private int disid;
	private String disname;
	private String distype;
	private String disstate;
	private int uid;
	private String disscope;
	private Double disprice;
	private int instation;


	public int getUid() {
		return uid;
	}

	public void setUid(int uid) {
		this.uid = uid;
	}

	public int getInstation() {
		return instation;
	}

	public void setInstation(int instation) {
		this.instation = instation;
	}

	public Double getDisprice() {
		return disprice;
	}

	public void setDisprice(Double disprice) {
		this.disprice = disprice;
	}

	public String getDisscope() {
		return disscope;
	}

	public void setDisscope(String disscope) {
		this.disscope = disscope;
	}



	public String getDisstate() {
		return disstate;
	}

	public void setDisstate(String disstate) {
		this.disstate = disstate;
	}

	public String getDistype() {
		return distype;
	}

	public void setDistype(String distype) {
		this.distype = distype;
	}

	public String getDisname() {
		return disname;
	}

	public void setDisname(String disname) {
		this.disname = disname;
	}

	public int getDisid() {
		return disid;
	}

	public void setDisid(int disid) {
		this.disid = disid;
	}


	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.resp = response;
	}
	
	@Resource
	private UpdateDisstationService updateDisstationService;
	
	
	public void updateDisstation(){
		resp.setCharacterEncoding("utf8");
		Cuser currentUser = (Cuser)session.get("cuser");
		String cuname = currentUser.getUname();
		int cuid = currentUser.getUid();
		System.out.println(uid);
		try {
			PrintWriter pw = resp.getWriter();
			if (updateDisstationService.getStataionExistsOrNot(disname, disid)==1) {
				pw.write("2");
				pw.flush();
				pw.close();
			} else {
				updateDisstationService.updateStationByInfo(disid, disname, uid, cuname, cuid, disscope, disprice, instation, distype, disstate);
				pw.write("1");
				pw.flush();
				pw.close();
			}
			
			
			
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	
}
